﻿@page "/ChartScatterSeries"

@inject ISalesInfoDataProvider Sales
@inject DemoConfiguration DemoConfiguration

<DemoPageSectionComponent Id="Charts-PointSeries-Scatter">
    <DemoChildContent>
        @inject IScatterRandomDataProvider Experiment

        <DxChart @ref="@chart"
                 T="DataPoint"
                 Width="100%"
                 Height="400px">
            <DxChartTitle Text="Random Points Generator"/>
            <DxChartScatterSeries T="DataPoint"
                                  TArgument="double"
                                  TValue="double"
                                  Data="points1"
                                  Name = "Population 1"
                                  ArgumentField="point=>point.Y"
                                  ValueField="point=>point.X">
                <DxChartSeriesPoint Symbol=ChartPointSymbol.Circle
                                    Size="5"
                                    HoverMode="ChartSeriesPointHoverMode.None" />
            </DxChartScatterSeries>
            <DxChartScatterSeries T="DataPoint"
                                  TArgument="double"
                                  TValue="double"
                                  Data="points2"
                                  Name = "Population 2"
                                  ArgumentField="point=>point.Y"
                                  ValueField="point=>point.X">
                <DxChartSeriesPoint Symbol=ChartPointSymbol.TriangleDown
                                    Size="5"
                                    HoverMode="ChartSeriesPointHoverMode.None" />
            </DxChartScatterSeries>
            <DxChartScatterSeries T="DataPoint"
                                  TArgument="double"
                                  TValue="double"
                                  Data="points3"
                                  Name = "Population 3"
                                  ArgumentField="point=>point.Y"
                                  ValueField="point=>point.X">
                <DxChartSeriesPoint Symbol=ChartPointSymbol.Square
                                    Size="5"
                                    HoverMode="ChartSeriesPointHoverMode.None"/>
            </DxChartScatterSeries>
            <DxChartLegend HoverMode="ChartLegendHoverMode.None"/>
        </DxChart>
    </DemoChildContent>

    <OptionsContent>
        <OptionChartExportComponent ExportMethod="@ExportChart" />
    </OptionsContent>

    @code {
        DxChartBase chart;
        IEnumerable<DataPoint> points1;
        IEnumerable<DataPoint> points2;
        IEnumerable<DataPoint> points3;

        async void ExportChart(ChartExportFormat format) {
        await chart?.ExportAsync("ScatterChart", format);
        }

        protected override async Task OnInitializedAsync() {
            int pointCount;
            if (DemoConfiguration.IsServerSide)
                pointCount = 1000;
            else
                pointCount = 500;
            points1 = await Experiment.GenerateCluster(140, 1280, 100, 1240, pointCount, 1);
            points2 = await Experiment.GenerateCluster(500, 1600, 1000, 2100, pointCount, 2);
            points3 = await Experiment.GenerateCluster(450, 950, 1550, 2050, pointCount, 3);
        }
    }
</DemoPageSectionComponent>
